package com.hjl.mybatis.servlet; /**
 * @author ServivE
 * @className ${NAME}
 * @description ${description}
 * @version 0.1
 * @date 2024/8/2 21:22
 * @since jdk11
 */

import com.hjl.mybatis.entity.Emp;
import com.hjl.mybatis.mapper.EmpMapper;
import com.hjl.mybatis.utils.SqlSessionFactoryUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "UpdateEmpServlet", value = "/empUpdate")
public class UpdateEmpServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int eid = Integer.parseInt(request.getParameter("eid"));
        String ename = request.getParameter("ename");
        String esex = request.getParameter("esex");
        Double sal = Double.valueOf(request.getParameter("sal"));
        Emp emp = new Emp(eid, ename, esex, sal);

        int i = SqlSessionFactoryUtil.getSqlSession().getMapper(EmpMapper.class).updateEmp(emp);
        if (i > 0) {
            response.sendRedirect("empInfo.html");
        }
    }
}
